import { createStore } from 'vuex'
import eventBus from 'vue3-eventbus';


export default createStore({
  state: {
    config: [], //结构
    stockInOrder: [], // 入库单添加
    personInfo: {},
    balanceShow: window.localStorage.getItem('balanceShow') ||  0,

    // 权限
    jurisdiction: JSON.parse(window.localStorage.getItem('jurisdiction') || '[]'),

    AllRecord: 0,
    ChargeCount: 0,
    hasChargeCount: 0,
    currentPath: window.localStorage.getItem('currentPath') ||  '/',


  },
  mutations: {
    setConfig(state, data) {
      state.config = data
    },

    setStockInOrder(state, data) {
      state.stockInOrder = data
    },

    setPersonInfo(state, data) {
      state.personInfo = data
    },

    setJurisdiction(state, data) {
      state.jurisdiction = data
      window.localStorage.setItem('jurisdiction', JSON.stringify(data))
      eventBus.emit('jurisdiction:update')
    },

    setBalanceShow(state, data) {
      state.balanceShow = data
      window.localStorage.setItem('balanceShow', JSON.stringify(data))
    },

    reMoveJurisdiction(state) {
      state.jurisdiction = []
    },


    // 得到今日就诊的数量
    getAllRecord(state, data) {
      state.AllRecord = data
    },

    // 今日待收费订单数量
    getChargeCount(state, data) {
      state.ChargeCount = data
    },

    gethasChargeCount(state, data) {
      state.hasChargeCount = data
    },


  },
  actions: {
    setConfig({commit}, data) {
      commit('setConfig', data)
    },

    setStockInOrder({commit}, data) {
      commit('setStockInOrder', data)
    },

    setPersonInfo({commit}, data) {
      commit('setPersonInfo', data)
    },

    // 设置权限
    getJurisdiction({commit}, data) {
      commit('setJurisdiction', data)
    },

    // 得到余额
    getBalanceShow({commit}, data) {
      commit('setBalanceShow', data)
    },

    setAllRecord({commit}, data) {
      commit('getAllRecord', data)
    },
    setChargeCount({commit}, data) {
      commit('getChargeCount', data)
    },

    sethasChargeCount({commit}, data) {
      commit('gethasChargeCount', data)
    },

  },
  modules: {
  }
})
